{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import nnmf "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6]])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m1= np.arange(1,7).reshape(2, 3)\n",
    "\n",
    "m1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[2, 3],\n",
       "       [4, 5],\n",
       "       [6, 7]])"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m2= np.arange(2,8).reshape(3, 2)\n",
    "m2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1,  4,  9],\n",
       "       [16, 25, 36]])"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m1*m1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 2,  8, 18],\n",
       "       [12, 25, 42]])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m1*m2.transpose()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2763.1719720708916\n",
      "6.385316986625388\n",
      "2.447999711110964\n",
      "0.7733602424443581\n",
      "0.29257595882211657\n",
      "0.13629725446574012\n",
      "0.0692988341027604\n",
      "0.03628358568537204\n",
      "0.019242796527209265\n",
      "0.010286813517213946\n",
      "0.0055307267794845625\n",
      "0.0029862969139598915\n",
      "0.0016175552042439788\n",
      "0.0008782232452634228\n",
      "0.00047764500171119543\n",
      "0.00026011374006024835\n",
      "0.00014178605433212864\n",
      "7.734073704239542e-05\n",
      "4.220930110062489e-05\n",
      "2.3044874354353265e-05\n",
      "1.2585296694027913e-05\n",
      "6.874536679864788e-06\n",
      "3.755697202910457e-06\n",
      "2.0520472383398517e-06\n",
      "1.1212974566853895e-06\n",
      "6.127473618598559e-07\n",
      "3.3485911039855925e-07\n",
      "1.8300274955836317e-07\n",
      "1.0001475415188343e-07\n",
      "5.466113331030895e-08\n"
     ]
    }
   ],
   "source": [
    "w,h = nnmf.factorize(m1*m2.transpose(),pc=3,iter=300)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[0.44042967, 0.21798678, 0.65820746],\n",
       "        [0.64617473, 1.48251286, 0.68160969]])"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[ 0.32639264,  0.13200972,  5.49289012],\n",
       "        [ 7.85076354, 13.28042919, 17.75647207],\n",
       "        [ 0.22037209,  7.66758925, 17.7908798 ]])"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "h"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[ 3.78799063, 18.04010956, 13.47858132],\n",
       "        [ 4.15061992, 36.86435551, 23.63613463]])"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w*h.transpose()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[ 2.00016624,  7.99996346, 17.99999777],\n",
       "        [11.99997233, 25.00001152, 42.00000105]])"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w*h"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 2,  8, 18],\n",
       "       [12, 25, 42]])"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m1*m2.transpose()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
